package org.springmvc.web.servlet.view;

import org.springmvc.web.servlet.View;
import org.springmvc.web.servlet.ViewResolver;

import java.util.Locale;

/**
 * @author marin
 * @version 1.0
 * @date 2025/9/1 19:58
 * @desc 内部资源视图解析器，可以解析JSP
 */
@SuppressWarnings("all")
public class InternalResourceViewResolver implements ViewResolver {

    private String prefix;

    private String suffix;


    /**
     * 将逻辑视图名称转为物理视图名称并以View对象返回
     * @param viewName
     * @param locale
     * @return
     * @throws Exception
     */
    @Override
    public View resolveViewName(String viewName, Locale locale) throws Exception {
        //创建视图对象
        InternalResourceView view = new InternalResourceView();
        //给视图对象赋值
        view.setContentType("text/html;charset=UTF-8");
        view.setPath(prefix + viewName + suffix);
        return view;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }
}
